<?php

/**
 * @package Skjb_Library
 */

/**
 * @package Skjb_Library
 */
class Skjb_View_Helper_GoogleAnalytics extends Zend_View_Helper_Abstract
{
    /**
     * return the code for Google Analytics
     */
    public function googleAnalytics($key)
    {
        $return = '';
        $return .= '<script type="text/javascript">' . "\n";
        $return .= 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");' . "\n";
        $return .= 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));' . "\n";
        $return .= '</script>' . "\n";
        $return .= '<script type="text/javascript">' . "\n";
        $return .= 'try {' . "\n";
        $return .= 'var pageTracker = _gat._getTracker("' . $key . '");' . "\n";
        $return .= 'pageTracker._trackPageview();' . "\n";
        $return .= '} catch(err) {' . "\n";
        $return .= '}' . "\n";
        $return .= '</script>' . "\n";
        return $return;
    }
}
